﻿using BCL.Tool;
using Devices;
using System.Windows;
using System.Windows.Controls;
namespace DevicesView.UCControl
{
    /// <summary>
    /// UCTestItem.xaml 的交互逻辑
    /// </summary>
    public partial class UCTestItem : UserControl
    {
        private ResultItem resultItem;
        public UCTestItem()
        {
            InitializeComponent();
        }

        public UCTestItem(Devices.ResultItem item)
        {
            resultItem = item;
            InitializeComponent();
            this.textName.Text = item.Display;
            this.textValue.Text = item.Value?.ToString();
            this.textRemarks.Text = item.Remarks;
            this.textUnit.Text = item.Unit;
            textMin.Text = item.Min;
            textMax.Text = item.Max;

            if (item.Type == (int)ResultItemType.PN)
            {
                textValue.Visibility = Visibility.Visible;
                this.checkboxPn.IsChecked = item.PN;
            }
            else
                textValue.Visibility = Visibility.Visible;
        }

        public ResultItem ResultItem
        {
            get {
                if (resultItem == null)
                    return null;
                resultItem.Value = textValue.Text;
                resultItem.Max = textMax.Text;
                resultItem.Min = textMin.Text;
                if (resultItem.Type == (int)ResultItemType.PN)
                {
                    bool pn = checkboxPn.IsChecked == null ? false : (bool)checkboxPn.IsChecked;
                    resultItem.PN = pn;
                    resultItem.Value = pn ? "阳性".Language():"阴性".Language();
                }
                resultItem.Remarks = textRemarks.Text;
                return resultItem;
            }
        }
    }
}
